<script type="text/javascript" charset="utf-8">
	$(function() {
		$('#dialog-form').load('<?php echo site_url(); ?>gadaian/popup');
		$("#dialog-form").dialog({
			autoOpen: false,
			title: 'No Rekening',
			height: 400,
			width: 712,
			modal: true,
			buttons: {
				'OK': function() {
					var chkIdx = $('input:radio:checked').val();
					var aData = popup_table.fnGetData(chkIdx);
					$("#no_rekeningID").val($("#id"+chkIdx).val());
					$("#no_rekening").val(aData[0]);
					$("#anggota_id").val(aData[1]);
					$("#nama_anggota").val(aData[2]);
					$("#saldo_sblm").val(aData[3]);
					$("#saldo_sblm2").val(aData[3]);
					//var x = document.getElementById("tbDescription").value;
					/*
					if($("#jenis_gadaian").val()=='2'){
						$("#biaya").val('10000');
					}else{
						$("#biaya").val('2000');
					}
					*/
					$(this).dialog('close');
				},
				'Batal': function() {
					$(this).dialog('close');
				}
			},
		});

		$('#no_rekening').focus(function() {
				$('#dialog-form').dialog('open');
			});

	});
	
</script>

<div class="post-title"><h2><a href="<?php echo current_url();?>"><?php echo $title; ?></a></h2></div>

<div class="post-body">

<div id="dialog-form"></div>

<?php
	echo form_open('transaksi_gadaian/'.$form_act, 'id="transaksi_gadaian_form"');

	echo "<div id='error' class='error-message' ";

	if($this->session->userdata('ERRMSG_ARR'))
	{
		echo ">";
		echo $this->session->userdata('ERRMSG_ARR');
		$this->session->unset_userdata('ERRMSG_ARR');
	}
	else
	{
		echo "style='display:none'>";
	}
	
	echo "</div>";

	$data['class'] = 'input';
	if ($act == 'view') $data['disabled'] = TRUE;
?>
	
	<table width="300" border="0" align="center" cellpadding="2" cellspacing="0">		
		<tr>
			<th colspan='2'>**No Transaksi otomatis dibuat </th>			
		</tr>
		<tr>
			<th><?php echo form_label('No Transaksi**','no_transaksi'); ?></th>
			<td>
				<?php 
					$data['name'] = $data['id'] = 'no_transaksi';
					if($act=='add')
					{ 
						if($new_id == ''){						
							$data['value'] = '0000001';
						}else{						
							$data['value'] = formatIdtransaksi_gadaian(substr($new_id->no_transaksi, 2) + 1);
						}
					}else{
						$data['value'] = (set_value('no_transaksi')) ? set_value('no_transaksi') : $transaksi_gadaian_data['no_transaksi'];
					}					
					$data['title'] = "No Transaksi tidak boleh kosong";
					
					echo form_hidden('no_transaksi',$data['value']);
					echo "<input size='50' value='$data[value]' disabled='1'/>";
					//echo form_input($data);
				?>
			</td>			
		</tr>		
		<tr>
			<th><?php echo form_label('No Rekening *','no_rekening'); ?></th>
			<td>
				<?php 
					echo form_hidden('no_rekeningID',$transaksi_gadaian_data['no_rekening_id']);

					//$data['name'] = $data['id'] = 'no_rekening';
					$data['value'] = (set_value('no_rekening')) ? set_value('no_rekening') : $transaksi_gadaian_data['no_rekening'];
					$data['title'] = "No Rekening tidak boleh kosong";
					echo "<img src=".base_url()."/images/b_search.png><input id='no_rekening' name='no_rekening' size='15' value='$data[value]' />";
					//echo form_input($data);
				?>
			</td>					
		</tr>		
		<tr>
			<th>
				<?php echo form_label('Nama Anggota','nama_anggota'); ?>
			</th>
			<td>
				<?php 
					$data['name'] = $data['id'] = 'anggota_id';
					//$data['name'] =  = 'anggota_id';					
					$data['value'] = (set_value('anggota_id')) ? set_value('anggota_id') : $transaksi_gadaian_data['anggota_id'];
					//echo 'test : ' . $data['value'];					
					echo form_hidden('anggota_id',$data['value']);
					
					
					$data['value'] = (set_value('nama_anggota')) ? set_value('nama_anggota') : $transaksi_gadaian_data['nama_anggota'];
										
					echo "<input id='nama_anggota' name='nama_anggota' size='50' class='required' value='$data[value]' disabled='1'/>";
				?>
			</td>
		</tr>
		
		<tr>
			<th><?php echo form_label('Tanggal Reg','tgl_reg'); ?></th>
			<td>
				<?php 
					$data['name'] = 'tgl_reg';
					$data['id'] = 'datepicker2';
					if($act=='add')
					{ 
						$data['value'] = date("Y-m-d");;
					}else{					
						$data['value'] = (set_value('tgl_reg')) ? set_value('tgl_reg') : $transaksi_gadaian_data['tgl_reg'];
					}
					$data['title'] = "Tanggal harus diisi dengan format dddd-mm-yy";				
					//echo form_input($data);
					echo "<input align='right' id='datepicker2' name='tgl_reg' size='10'  value='$data[value]' />";
				?>
			</td>				
		</tr>
		<tr>
			<th>
				<?php echo form_label('Saldo','saldo_sblm'); ?>
			</th>
			<td>
				<?php 
					$data['name'] = $data['id'] = 'saldo_sblm';
					
					//$nilai = $data['value'];
					//$nilai = str_replace (" ", "", $nilai);
					//$nilai = str_replace (".", "", $nilai);
					//$nilai = str_replace ("Rp", "", $nilai);

					//echo $nilai;
					$data['value'] = (set_value('saldo_sblm')) ? set_value('saldo_sblm') : $transaksi_gadaian_data['saldo_sblm'];					
					echo form_hidden('saldo_sblm',$data['value']);
					
					$data['value'] = 'Rp'.number_format(($data['value']), 0, '', '.') . ',00';
					echo "<input align='right' id='saldo_sblm2' size='50' disabled='1' value='$data[value]' />";
				?>
			</td>
		</tr>
		<tr>
			<th>
				<?php echo form_label('Jenis gadaian','jenis_gadaian'); ?>
			<td>
				<?php 
					echo "<select name='jenis_gadaian'>";
					$tampil=mysql_query("SELECT * FROM jenis_gadaian ORDER BY id");

					  while($w=mysql_fetch_array($tampil)){
						if ($transaksi_gadaian_data['jenis_gadaian']==$w['id']){
						  echo "<option value=$w[id] selected>$w[id_jenis_gadaian]</option>";
						}
						else{
						  echo "<option value=$w[id]>$w[id_jenis_gadaian]</option>";
						}
					  }
					 echo "</select>";
				?>					
			</td>
		</tr>	
		
		<tr>
			<th>
				<?php echo form_label('Sandi Simpanan','sandi_simp'); ?>
			</th>
			<td>
				<?php 
					echo "<select name='sandi_simp'>";
					$tampil=mysql_query("SELECT * FROM sandi_simp ORDER BY id");

					  while($w=mysql_fetch_array($tampil)){
						if ($transaksi_gadaian_data['sandi_simp']==$w['id']){
						  echo "<option value=$w[id] selected>$w[id_sandi_simp] - $w[keterangan]</option>";
						}
						else{
						  echo "<option value=$w[id]>$w[id_sandi_simp] - $w[keterangan]</option>";
						}
					  }
					 echo "</select>";
				?>
			</td>
		</tr>		
		<tr>
			<th><?php echo form_label('Jumlah Biaya','biaya'); ?></th>
			<td>
				<?php 
					$data['name'] = $data['id'] = 'biaya';
					$data['value'] = (set_value('biaya')) ? set_value('biaya') : $transaksi_gadaian_data['biaya'];
					$data['title'] = "Perkiraan biaya harus diisi angka";
								
					/*
					if($act=='add')
					{ 
						$data['value'] = 0;
					}else{					
						$data['value'] = (set_value('biaya')) ? set_value('biaya') : $transaksi_gadaian_data['biaya'];
					}
					*/
					
					if($act=='add')
					{ 
						$data['value'] = 0;
						?>
						<input type=text id='biaya' name='biaya' size='50' value='Rp0,00' align=right onkeypress='return numbersonly(this, event)' onBlur='this.value=formatIDR(this.value);' class='required' onClick='this.value=unFormatIDR(this.value);' maxlength='20'>
						
						<?php
					}else{					
						$data['value'] = (set_value('biaya')) ? set_value('biaya') : $transaksi_gadaian_data['biaya'];
						?>
						<input type=text id='biaya' name='biaya' size='50' value='<?php echo 'Rp'.number_format(($data['value']), 0, '', '.') . ',00'; ?>' align=right onkeypress='return numbersonly(this, event)' onBlur='this.value=formatIDR(this.value);' class='required' onClick='this.value=unFormatIDR(this.value);' maxlength='20'>
						<?php
						
					}
					
					
					//echo "<input align='right' id='biaya' name='biaya' size='50' class='required number' value='$data[value]' />";
				?>
			</td>	
		</tr>	
		<tr>
			<th>
				<?php echo form_label('Keterangan','keterangan'); ?>
			</th>
			<td>
				<?php 
					$data['name'] = $data['id'] = 'keterangan';
					$data['value'] = (set_value('keterangan')) ? set_value('keterangan') : $transaksi_gadaian_data['keterangan'];
					unset($data['title']);
					//echo form_textarea($data);
					echo "<textarea id='keterangan' name='keterangan' cols='50' value='$data[value]' /></textarea>";
				?>
			</td>
		</tr>	
	</table>
	
	<div class="buttons">
		<?php 
			if($act!='view')
			{ 
				echo form_submit('simpan','Simpan', "id = 'button-save'" );
				echo form_reset('reset','Reset', "id = 'button-reset'" );
				echo form_button(array('id' => 'button-cancel', 'content' => 'Batal', 'onClick' => "location.href='".site_url()."transaksi_gadaian'" ));
			}
			else
			{
				echo form_button(array('id' => 'button-cancel', 'content' => 'Kembali', 'onClick' => "location.href='".site_url()."transaksi_gadaian'" ));
			}
		?>				
	</div>
	
<?php echo form_close(); ?>

</div>

<script type='text/javascript'>
	//Validasi di client
	$(document).ready(function()
	{
		$('#transaksi_gadaian_form').validate({
			errorLabelContainer: "#error",
			wrapper: "li",
			rules: 
			{
				no_rekening: "required",
				tgl_reg: "dateISO",				
			}
		});
	});
</script>
<?php
	function formatIdtransaksi_gadaian($id){		
		if (strlen($id) == 1)
		{
			return '000000' . $id;
		}
		else if (strlen($id) == 2)
		{
			return '00000' . $id;
		}
		else if (strlen($id) == 3)
		{
			return '0000' . $id;
		}
		else if (strlen($id) == 4)
		{
			return '000' . $id;
		}
		else if (strlen($id) == 5)
		{
			return '00' . $id;
		}
		else if (strlen($id) == 6)
		{
			return '0' . $id;
		}
		else {
			return $id;
		}
	}
?>